package com.wt.admin.service.ai.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wt.admin.domain.dto.ai.AgentsInfoDTO;
import com.wt.admin.domain.entity.ai.AgentsInfoEntity;
import com.wt.admin.domain.vo.ai.AgentsInfoVO;
import com.wt.admin.mapper.ai.AgentsInfoMapper;
import com.wt.admin.service.ai.AgentsInfoService;
import com.wt.admin.service.ai.impl.agents.AgentsManager;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AgentsInfoServiceImpl extends ServiceImpl<AgentsInfoMapper, AgentsInfoEntity> implements AgentsInfoService {

    @Resource
    private AgentsInfoMapper agentsInfoMapper;
    @Resource
    AgentsManager agentsManager;

    @Override
    public List<AgentsInfoVO> infoList(AgentsInfoDTO data) {
        return agentsInfoMapper.infoList(data);
    }

    @Override
    public AgentsInfoVO infoEdit(AgentsInfoDTO data) {
        saveOrUpdate(data);
        agentsManager.create(data);
        return BeanUtil.copyProperties(data,AgentsInfoVO.class);
    }

    @Override
    public AgentsInfoVO infoDel(AgentsInfoDTO data) {
        removeById(data.getId());
        agentsManager.remove(data.getId());
        return null;
    }

    @Override
    public void classDel(Integer id) {
        agentsInfoMapper.classDel(id);
    }

    public void init(){
        infoList(null)
                .forEach(i-> {
                    AgentsInfoDTO agentsInfoDTO = BeanUtil.copyProperties(i, AgentsInfoDTO.class);
                    agentsManager.create(agentsInfoDTO);
                });
    }

}
